#include "./common.h"
FILE *fp;
int multu(unsigned long a,unsigned long b,unsigned int reflo,unsigned int refhi,unsigned long lo,unsigned long hi){
    unsigned long c=a*b;
    c +=(lo+(hi<<32));
    unsigned tmplo = (unsigned) (c&0xffffffff);
    unsigned tmphi = (unsigned) (c>>32);
    return tmplo==reflo && tmphi == refhi;
}

void gen_maddu(){

    fprintf(fp,"TEST_MType(");
    unsigned long a=(unsigned long)getRandInt32();
    unsigned long b=(unsigned long)getRandInt32();
    unsigned long oldlo=(unsigned long)getRandInt32();
    unsigned long oldhi=(unsigned long)getRandInt32();
    unsigned long c = a*b;
    c+=((oldhi<<32)+oldlo);
    unsigned tmplo=(unsigned)(c&0xffffffff);
    unsigned tmphi=(unsigned)(c>>32);
    fprintf(fp,"0x%08x,0x%08x,0x%08x,0x%08x,0x%08x,0x%08x,maddu)\n",(unsigned)a,(unsigned)b,tmplo,tmphi,(int)oldlo,(int)oldhi);
}

int main(int argc, char const *argv[])
{
    // fp=fopen("../asm/maddu.S","w");
    // srand(time(NULL));
    // for (int i = 0; i < 50; i++)
    // {
        // gen_maddu();
    // }
    int i=0;
i=multu(0xc8239607,0xe9e01339,0xed834170,0xd0e5006b,0x145454e1,0xcc1117f5);
    printf("%d\n",i);
i=multu(0x7dfcbce1,0x0d797e64,0x338ad8b3,0x25e391f6,0xe48152cf,0x1f41f1b6);
    printf("%d\n",i);
i=multu(0xddf11d3e,0x6fec766e,0xbb86dc6a,0x0d757160,0x6349b7c6,0x1c595b2d);
    printf("%d\n",i);
i=multu(0xc9bd94f7,0x58cfcb32,0xbc6d5014,0x4abb516b,0xa48d5ad6,0x5d8e30fd);
    printf("%d\n",i);
i=multu(0xca66720b,0xbe2bcec9,0xfbc781aa,0xb7d81518,0x4fba1d07,0xaa0faa96);
    printf("%d\n",i);
i=multu(0xdde420ae,0x5caa0f2b,0x3308b8a9,0x5fa5a1d4,0x5441096f,0x6bfe4e9d);
    printf("%d\n",i);
i=multu(0x3ba927b8,0xe66f4a72,0x70328577,0x8d0b5dd2,0x709ba587,0x93009c29);
    printf("%d\n",i);
i=multu(0x2052317e,0x87495574,0xbb8782a5,0xe1ae830a,0x3cec3f8d,0xf0ec1a35);
    printf("%d\n",i);
i=multu(0xb60d06b3,0xc38c4fa8,0xc72cd2bd,0x78da4dc0,0x46ab3045,0x6763f03c);
    printf("%d\n",i);
i=multu(0x8a32266f,0xd99e63e5,0x93414e02,0x52084851,0xc005ffb7,0x405ecf31);
    printf("%d\n",i);
i=multu(0x91b5503d,0xe569f881,0x7c43f142,0x11389eb2,0xf0266a85,0x05c465db);
    printf("%d\n",i);
i=multu(0x4d649a5f,0x2bf09da1,0xb8416ccf,0x8a1f4b54,0xab401410,0x7cd6a76f);
    printf("%d\n",i);
i=multu(0xf4136591,0xc7a0046f,0x9f4dab6a,0xc7416001,0x4bae5d8b,0xc4a125b4);
    printf("%d\n",i);
i=multu(0x63d1eb35,0x0b8b1a1d,0x2951a5e2,0xe5112ec4,0x8bdf9ee1,0xe090ec80);
    printf("%d\n",i);
i=multu(0xda2691f2,0xbeae99d3,0x67e56620,0xa3c97355,0xbe6579aa,0x9a21357d);
    printf("%d\n",i);
i=multu(0x4590dc6f,0x194ffaa3,0x52edd51c,0xcddd33ba,0xb32c146f,0xc6fc5264);
    printf("%d\n",i);
i=multu(0x4f70f9da,0x2b5850b5,0x0b0c5c1c,0xb0d7d357,0x112794fa,0xa364717e);
    printf("%d\n",i);
i=multu(0x4877a168,0x18c56baf,0xb3566005,0xe8000643,0x341091ed,0xe0fcec97);
    printf("%d\n",i);
i=multu(0x8dc665d1,0xf062fc7a,0xee328738,0x49cab02a,0x276a459e,0x42d3413c);
    printf("%d\n",i);
i=multu(0x074b362e,0xf8b41594,0x98fb3aa7,0xd2eb200d,0x8db6220f,0xd3205840);
    printf("%d\n",i);
i=multu(0x31b34135,0xa325d0cf,0x3f84ed51,0xb624e262,0x3eef2376,0xc82ba9a0);
    printf("%d\n",i);
i=multu(0x219c6652,0xbc01389b,0x373424e4,0xc77ba5a1,0x08ce413e,0xd06907c4);
    printf("%d\n",i);
i=multu(0xbca9ab9b,0xd124040c,0xf6bead79,0xb497a438,0xcb503635,0xa84443ef);
    printf("%d\n",i);
i=multu(0xb22d86f1,0xefe5de46,0xc8b5a560,0x030dea65,0xe0a8c17a,0xfe28d134);
    printf("%d\n",i);
i=multu(0xeace3e10,0xec1aaa14,0x42cc5d8f,0xa61e03bf,0xe7d8e44f,0xa47855bb);
    printf("%d\n",i);
i=multu(0xe3ac91a5,0x0f707a44,0x17e7055b,0x1e743588,0xfd77b387,0x20298b07);
    printf("%d\n",i);
i=multu(0x7e3b6e42,0x309f3ae3,0xfff6f45b,0xa9137097,0xbf4b3bd5,0x9119c7f9);
    printf("%d\n",i);
i=multu(0x67629d72,0x4ea3943b,0x0e505482,0xc7fdbfeb,0x3bfa233c,0xa83ba44b);
    printf("%d\n",i);
i=multu(0x2f2c2105,0x254cca92,0x771824c7,0x05c8c878,0x37635ded,0xfee94145);
    printf("%d\n",i);
i=multu(0x205ae682,0x78d87be1,0xd9e3b9c1,0x7807cc41,0x4f8eab7f,0x68c1d3da);
    printf("%d\n",i);
i=multu(0x68078de4,0xff4aae32,0x7216a8d6,0xc872c220,0xde43fa4e,0xc8bc70b6);
    printf("%d\n",i);
i=multu(0x6e9be397,0x0fd87f1d,0x6796ca8e,0x8b16c0ca,0xa99e1973,0x843e1401);
    printf("%d\n",i);
i=multu(0xacb9738d,0xb31ebbb7,0xef9c6d62,0x7762ef91,0xde1cd497,0x5e60b6a8);
    printf("%d\n",i);
i=multu(0xa180c3fd,0x9adebb19,0x6c5e2c28,0xa12c7bc6,0x703b3973,0x7bd80143);
    printf("%d\n",i);
i=multu(0x98bbd881,0x00ff1967,0x080ed7ff,0x11b7e932,0x93d72318,0x121ed055);
    printf("%d\n",i);
i=multu(0x3e29cc37,0xfaa538ad,0x72c9dee6,0x18ccde41,0xf66bd5bb,0x1a19ba57);
    printf("%d\n",i);
i=multu(0xddd4961c,0x987b5ee7,0xc472b99f,0x07848444,0xcb0cfe5b,0xf9b358c7);
    printf("%d\n",i);
i=multu(0xe2e175b4,0x4180252b,0x0690c45a,0x5e293679,0xc6aefb1e,0x659c8b16);
    printf("%d\n",i);
i=multu(0xc61a8680,0xd66aa66e,0x227b1830,0x0a3a9e2f,0x1ede4d30,0x00d316e8);
    printf("%d\n",i);
i=multu(0x5dab795a,0x8e6c33d4,0xe06ffe15,0x9256e0ea,0x074a918d,0xbbe5a5a7);
    printf("%d\n",i);
i=multu(0x8d577add,0x927b6f40,0xc7d7dd74,0xf5ff5bf8,0x71845334,0xc4f23b8f);
    printf("%d\n",i);
i=multu(0xa0c0dbe6,0xe4035ec1,0x33f02c5c,0x438efc51,0xc619eff6,0x3925555d);
    printf("%d\n",i);
i=multu(0x6834d0d4,0xe626200d,0x7aaff39a,0x59955f18,0x1e6ed8d6,0x641b376b);
    printf("%d\n",i);
i=multu(0x20dad516,0x9ca60a2f,0xc76770f0,0xa1a471e1,0x9ea375e6,0xae649dea);
    printf("%d\n",i);
i=multu(0xacecb464,0x7ba09606,0xbcaffd27,0x2b1c1a3e,0x32f12acf,0x533a7c51);
    printf("%d\n",i);
i=multu(0x333c4413,0xd53f881b,0x8a61fc1a,0x585f754b,0x8f2fb619,0x60eddda9);
    printf("%d\n",i);
i=multu(0xb95f83cf,0x9fe7c741,0xbc0aac17,0xb959360c,0xea8b4b88,0x9ed658c7);
    printf("%d\n",i);
i=multu(0xe61d8c3e,0xa18b0fce,0x9eb08eb0,0xba48ec4c,0x940812cc,0xb0bbf2e6);
    printf("%d\n",i);
i=multu(0x6f30451e,0xfc5d285f,0x732f53ba,0xca19f626,0x0192fd98,0xcbae4129);
    printf("%d\n",i);
i=multu(0x46147184,0x21f195ca,0x566f6a27,0x19349b08,0x42f803ff,0x0fe9d626);
    printf("%d\n",i);
    return 0;
}
